﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data;
using Jumpton.SFA.Server.BusinessRule;

public partial class WelcomePage : PageBase
{
    public string dataGrid = "";
    public string dataChart = "";
    public string totalT = "";
    public string totalS = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            SelectData();
        }
    }

    public void SelectData()
    {
        ReportData Report = new ReportData();
        DataSet ds = Report.getSalesPerformance(MyStateManager.DomainID, MyStateManager.UsersID);
        if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
        {
            dataGrid = "{Table:[]}";
            dataChart = "{Table:[{data: [[\"未完成\",100]]}]}";
            return;
        }
        dataGrid = BusinessRule.JsonHelper.DataTableToJson(ds.Tables[0]);

        dataChart += "{Table:[{data: [";
        int cou = ds.Tables[0].Rows.Count - 1;
        for (int i = 0; i <= cou; i++)
        {
            if (i == 0)
            {
                dataChart += "{";
                dataChart += string.Format("name: \"{0}\",y: {1},sliced: true,selected: true", ds.Tables[0].Rows[i]["NAME"], ds.Tables[0].Rows[i]["T_S"]);
                dataChart += ((i == cou) ? "}" : "},");
                continue;
            }
            dataChart += "{";
            dataChart += string.Format("name: \"{0}\",y: {1}", ds.Tables[0].Rows[i]["NAME"], ds.Tables[0].Rows[i]["T_S"]);
            dataChart += ((i == cou) ? "}" : "},");
        }
        dataChart += "]}]}";
        totalT = ds.Tables[1].Rows[0]["T_O_S"].ToString();
        totalS = ds.Tables[1].Rows[0]["T_T_S"].ToString();
    }

    [WebMethod]
    public static string SelectMethodDate(decimal Domain_ID, DateTime Start_Date, DateTime End_Date, string Users_ID)
    {
        ReportData Report = new ReportData();
        DataSet ds = Report.getVisitExecution(Domain_ID, Start_Date, End_Date, Users_ID);

        if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
            return "";
        string sb = BusinessRule.JsonHelper.DataSetToJson(ds);
        return sb;
    }
}